import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.User;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

//mybatis快速入门代码
public class MybatisDemo {
    public static void main(String[] args) throws IOException {
//        1.加载mybatis的核心配置文件，获取sqlSessionFactory
        String resource="mybatis.xml";
        InputStream resourceAsStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);

//        2.获取sqlSession对象，用来执行sql
        SqlSession sqlSession = build.openSession();
//        3.执行sql
        List<User> objects = sqlSession.selectList("test.selectBlog");
        System.out.println("objects = " + objects);
    }
}
